package top.aicey.ai.sparring.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import top.aicey.ai.sparring.common.constants.EntityConstants;
import top.aicey.ai.sparring.dto.enums.SceneStatusEnum;
import top.aicey.ai.sparring.dto.res.SceneResponse;
import top.aicey.ai.sparring.entity.Scene;
import top.aicey.ai.sparring.mapper.SceneMapper;
import top.aicey.ai.sparring.service.ISceneService;

/**
 * <p>
 * 企业场景信息 服务实现类
 * </p>
 *
 * @author 白杨
 * @since 2025-01-14
 */
@Service
public class SceneServiceImpl extends ServiceImpl<SceneMapper, Scene> implements ISceneService {

    /**
     * 场景陪练次数增加
     *
     * @param moduleId
     * @param sceneId
     */
    @Override
    public void numAdd(Long sceneId) {
        getBaseMapper().numAdd(sceneId);
    }

    @Override
    public PageInfo<SceneResponse> pageQuery(Integer pageNumber, Integer pageSize, String moduleId) {
        Page<Scene> page = PageHelper.startPage(pageNumber,pageSize);
        page.doSelectPageInfo(()->{
            this.list(Wrappers.query(Scene.class).eq("status", SceneStatusEnum.RELEASE.getValue()).eq(
                EntityConstants.MODULE_ID, moduleId).orderByDesc(EntityConstants.CREATED_AT));
        });

        PageInfo<SceneResponse> pageInfo = page.toPageInfo(v -> {
            SceneResponse response = new SceneResponse();
            response.setId(v.getId());
            response.setName(v.getName());
            response.setIcon(v.getIcon());
            response.setSceneDescribe(v.getSceneDescribe());
            response.setCreateTime(v.getCreatedAt());
            return response;
        });
        return pageInfo;
    }

}
